<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\common\manager\prepay;
use app\common\manager\BaseManager;
use app\common\manager\prepay\gateway\Recharge;
use app\common\manager\prepay\gateway\Group;
use app\common\manager\prepay\gateway\Purchase;
use app\common\manager\prepay\gateway\Match;
use app\common\manager\prepay\gateway\Withdraw;
use app\common\manager\prepay\gateway\Transfer;
use app\common\manager\prepay\gateway\Assistant;
use think\Exception;

class PrepayManager extends BaseManager
{
    const RELATION_TYPE_RECHARGE = 'Recharge';
    const RELATION_TYPE_WITHDRAW = 'Withdraw';
    const RELATION_TYPE_GROUP = 'Group';
    const RELATION_TYPE_MATCH = 'Match';
    const RELATION_TYPE_TRANSFER = 'Transfer';
    const RELATION_TYPE_PURCHASE = 'Purchase';
    const RELATION_TYPE_ASSISTANT = 'Assistant';


    const RELATION_ARRAY = [
        self::RELATION_TYPE_RECHARGE,
        self::RELATION_TYPE_WITHDRAW,
        self::RELATION_TYPE_GROUP,
        self::RELATION_TYPE_MATCH,
        self::RELATION_TYPE_TRANSFER,
        self::RELATION_TYPE_PURCHASE,
        self::RELATION_TYPE_ASSISTANT,
    ];
    private static $result;
    public static function __callStatic ($name,$request)
    {
        $trans = !isset($request[2]);
        self::exec($request[0],$request[1],$trans);
    }

    public static function exec($user,$request,$trans=true)
    {
        try {
            $relationType = $request['relationType'];
            $orderModel = null;
            switch ($relationType) {
                case self::RELATION_TYPE_RECHARGE:
                    $orderModel = new Recharge();
                    break;
                case self::RELATION_TYPE_WITHDRAW:
                    $orderModel = new Withdraw();
                    break;
                case self::RELATION_TYPE_GROUP:
                    $orderModel = new Group();
                    break;
                case self::RELATION_TYPE_MATCH:
                    $orderModel = new Match();
                    break;
                case self::RELATION_TYPE_TRANSFER:
                    $orderModel = new Transfer();
                    break;
                case self::RELATION_TYPE_PURCHASE:
                    $orderModel = new Purchase();
                    break;
                case self::RELATION_TYPE_ASSISTANT:
                    $orderModel = new Assistant();
                    break;
            }
            $result = $orderModel->order($user,$request,$trans);
            self::setResult($result);
        }catch (Exception $exception){
            self::setResult(['code'=>self::$failCode,'message'=>$exception->getMessage().$exception->getLine().$exception->getFile()]);
        }


    }

    private static function setResult($result): void
    {
        self::$result = $result;
    }

    public static function getResult()
    {
        return self::$result;
    }
}